package com.kmstech.greeting.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="GREETINGS")
public class Greeting extends Identify {
  private static final long serialVersionUID = 20110713L;

  private String _language;
  private String _message;
  
  @SuppressWarnings("unused")
  // JPA call it
  private Greeting() {
  }
  
  public Greeting(String language, String message) {
    _language = language;
    _message = message;
  }

  @Column(name="LANG", length=2, nullable=false)
  public String getLanguage() {
    return _language;
  }

  public void setLanguage(String language) {
    _language = language;
  }

  @Column(name="MESSAGE", length=64)
  public String getMessage() {
    return _message;
  }

  public void setMessage(String message) {
    _message = message;
  }

  @Override
  public int hashCode() {
    return _language.hashCode();
  }
  
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof Greeting) {
      return _language.equalsIgnoreCase(((Greeting) obj)._language);
    }
    
    return false;
  }
  
  @Override
  public String toString() {
    return String.format("Greeting[%s=%s]", _language, _message);
  }
}
